#include "video.h"
#include "CodecWrapper.hpp"
#include "h264/codecs.h"

CodecWrapper* CodecWrapper::CreateCodecWrapper(CodecWrapper::Type type) {
	if (type != CodecWrapper::Type::H264) {
		return nullptr;
	}
	return  new CodecWrapper(type);
}

void CodecWrapper::Release(CodecWrapper** wrapper) {
	if (nullptr == wrapper) {
		return;
	}
	if (nullptr == *wrapper) {
		return;
	}
	
	delete *wrapper;
	wrapper = nullptr;
}

CodecWrapper::CodecWrapper(Type type) {
	this->impl = VideoCodecFactory::CreateDecoder(VideoCodec::H264);
}

CodecWrapper::~CodecWrapper() {
	if (this->impl != nullptr) {
		delete this->impl;
		this->impl = nullptr;
	}
}
	
void CodecWrapper::IsOutYUV(bool isOut){
	if (this->impl != nullptr) {
		this->impl->outputYuv = isOut;
	}
}

void CodecWrapper::IsOutRGB(bool isOut){
	if (this->impl != nullptr) {
		this->impl->outputBgr = isOut;
	}
}	

bool CodecWrapper::IsKeyFrame() {
	return this->impl->IsKeyFrame();
}

bool CodecWrapper::DecodePacket(uint8_t *buffer, int size, uint16_t lost, bool mark){
	return this->impl->DecodePacket(buffer, size, lost, mark);
}
void CodecWrapper::SetScale(uint32_t width, uint32_t height) {
	this->impl->SetScale(width, height);
}
int CodecWrapper::GetWidth() {
	return this->impl->GetWidth();
}

int CodecWrapper::GetHeight() {
	return this->impl->GetHeight();
}

uint8_t* CodecWrapper::GetFrame() {
	return this->impl->GetFrame();
}
uint8_t*  CodecWrapper::GetFrameBgr() {
	return this->impl->GetFrameBgr();
}
uint8_t*  CodecWrapper::GetFrameYuv()  {
	return this->impl->GetFrameYuv();
}